package com.itheima.springbootwebtlias.service.impl;

import com.itheima.springbootwebtlias.mapper.ClazzMapper;
import com.itheima.springbootwebtlias.mapper.EmpMapper;
import com.itheima.springbootwebtlias.mapper.StuMapper;
import com.itheima.springbootwebtlias.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    EmpMapper empMapper;

    @Autowired
    StuMapper stuMapper;

    // 员工职位统计
    @Override
    public Map jobCount() {
        // 1. 调用持久层 EmpMapper，统计职位信息
        List<Map> jobList = empMapper.jobCount();

        // 2. 处理查询结果
        Map map = new HashMap<>();
        map.put("jobList", jobList.stream().map(item->item.get("name")).collect(Collectors.toList()));
        map.put("dataList", jobList.stream().map(item->item.get("value")).collect(Collectors.toList()));

        // 3. 返回响应结果
        return map;
    }

    //  员工性别统计
    @Override
    public List<Map> genderCount() {
        //1. 调用持久层 EmpMapper，查询性别统计数据
        return empMapper.genderCount();
    }

    // 班级学生人数统计
    @Override
    public Map stuCount() {
        // 1. 调用持久层 ClazzMapper，查询班级学生人数统计数据
        List<Map> claList = stuMapper.stuCount();

        // 2. 处理查询结果
        Map map = new HashMap<>();
        map.put("clazzList", claList.stream().map(item->item.get("name")).collect(Collectors.toList()));
        map.put("dataList", claList.stream().map(item->item.get("value")).collect(Collectors.toList()));

        // 3. 返回响应结果
        return map;
    }

    // 学员学历统计
    @Override
    public List<Map> degreeCount() {
        return stuMapper.degreeCount();
    }

}
